import '../../css/app.css';
import 'virtual:svg-icons-register'
import {createInertiaApp} from '@inertiajs/vue3';
import {resolvePageComponent} from 'laravel-vite-plugin/inertia-helpers';
import type {DefineComponent} from 'vue';
import {createApp, h} from 'vue';
import {ZiggyVue} from 'ziggy-js';
import {createPinia} from 'pinia'
import ArcoVue from '@arco-design/web-vue';
import ArcoVueIcon from '@arco-design/web-vue/es/icon'
import '@arco-design/web-vue/dist/arco.css';

import '@/assets/styles/app.css';

const appName = import.meta.env.VITE_APP_NAME || '预约收银系统';
const pinia = createPinia()

createInertiaApp({
    title: (title) => (title ? `${title} - ${appName}` : appName),
    resolve: resolvePage,
    setup({ el, App, props, plugin }) {
        createApp({ render: () => h(App, props) })
            .use(plugin)
            .use(pinia)
            .use(ArcoVue)
            .use(ArcoVueIcon)
            .use(ZiggyVue)
            .mount(el);
    },
    progress: {
        color: '#4B5563',
    },
}).catch(reason => {
    console.log(reason);
});

function resolvePage(name: string) {
    const pages = import.meta.glob<DefineComponent>('../pages/**/*.vue');
    return resolvePageComponent<DefineComponent>(`../pages/${name}.vue`, pages);
}
